#include"Epoller.hpp"
#include"Tcpserver.hpp"  //处理IO
#include"Calculator.hpp" //处理业务
#include"Log.hpp"
#include<memory>
#include<functional>

Calculator calculator;

void DefaultOnMessage(shared_ptr<Connection> connection_ptr)
{
    lg(Debug, "上层已经得到数据\b");
    //处理数据
    string response = calculator.Handler(connection_ptr->Inbuffer());
    if(response.empty()) return;

    //发送出去
    lg(Debug, "%s", response.c_str());
    //response发送出去
    connection_ptr->AppendOutbuffer(response);  //将结果拷贝到输出缓冲区里面。
    //正确理解发送
    connection_ptr->_tcp_server_ptr->Sender(connection_ptr);
}

int main()
{

    unique_ptr<TcpServer> epoll_svr(new TcpServer(8080, DefaultOnMessage));
    epoll_svr->Init();
    epoll_svr->Loop();


    return 0;
}